import { getAuthors } from '@/models';
import { gfetch } from '@/utils/back/fetch';
import { cookies } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';

export async function getProductList(request: NextRequest) {
  const { searchParams } = request.nextUrl;

  const data = await gfetch<Obj>(
    `${process.env.NEXT_PUBLIC_DSZ_API_DOMAIN}/v2/products?${searchParams.toString()}`
  );
  return NextResponse.json(data);
}
export async function getProductDetail(request: NextRequest) {
  const { searchParams } = request.nextUrl;
  const data = await gfetch<Obj>(
    `${process.env.NEXT_PUBLIC_DSZ_API_DOMAIN}/v2/products?${searchParams.toString()}`
  );
  // const searchObject = Object.fromEntries(searchParams);
  // const skus = (searchObject.skus||'').split(',')
  // const res = data.data?.result.find((p:any) => skus.includes(p.sku));
  const res = data?.data?.result?.at(0);
  // console.log('🎁🎁🎁🎁> ', data?.data?.result);
  return { data: res || null, success: true, message: 'ok' };
}
